package com.hspedu.newData.力扣周赛.周赛.第449;

import org.junit.Test;

import java.util.Arrays;
import java.util.Map;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-11 
 * @Version: 1.0
 */

public class Q1不同字符数量最多为k时的最少删除数 {

    public int minDeletion(String s, int k) {
        int[] ans = new int[26];
        for (int i = 0; i < s.length(); i++) {
            ans[s.charAt(i) - 'a'] ++;
        }

        Arrays.sort(ans);

        int count = 0;
        for (int i = 25; i > 25 - k; i--) {
            count += ans[i];
        }

        return s.length() - count;
    }

    @Test
    public void test() {
        // 测试代码

        int i = minDeletion("aabb", 2);
        int i1 = minDeletion("abc", 2);
        int i2 = minDeletion("yyyzz", 1);
        int i3 = minDeletion("abcdef", 2);
        System.out.println("---");
    }

}
